@isTest
private class SalesOrderControllerTest {
    static testMethod void testMethod1() {
        

        Account acc = TestUtils.createAccount();
        acc.Name = '客户A';
        acc.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('TerminalCustomerAbroad','Account');
       
        insert acc;

        Product__c p1 = TestUtils.createProduct();
        p1.Category0__c = '试剂';
        p1.PriceCompany__c = 'MKSY';
        p1.ProductName__c = '测试试剂';
        p1.NCCode__c = '000001';
        p1.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');
        insert p1; 

        PriceList__c pl = new PriceList__c();
        pl.Product__c = p1.Id;
        pl.SalesCode__c = '05';
        pl.Price__c = 100;
        pl.Account__c = acc.Id;
        pl.ApplicableCustomers__c  = acc.Id;
        pl.Company__c = [select SubCompany__c from User where Id =:UserInfo.getUserId()].SubCompany__c;

        insert pl;


        ReturnSlip__c  rsp = new ReturnSlip__c();
        rsp.PreferentialAmount__c = 10;
        insert rsp ;


        SalesOrderController src = new SalesOrderController();
        src.backId = acc.Id; 
        src.init();
        Map<String,String> searchMap = new Map<String,String>();
        searchMap.put('ProductName__c','测试');
        src.searchJson = EncodingUtil.urlEncode(JSON.serialize(searchMap),'UTF-8');
        src.search();

        Map<String,Object>saveMap = new Map<String,Object>();
        saveMap.put('detial',JSON.deserializeUntyped( EncodingUtil.urlDecode(src.dataJson, 'UTF-8')));
        Map<String,String>orderMap = new Map<String,String>();
        orderMap.put('TransactionTerms__c','FOB');
        orderMap.put('PaymentMethod__c','其他');
        orderMap.put('InvoiceAddress__c','111');
        orderMap.put('InvoiceContact__c','111');
        orderMap.put('ReceiverContactInformation__c','111');
        orderMap.put('Consignee__c','111');
        orderMap.put('ConsigneeContactInformation__c','111');
        orderMap.put('ReceivingAddress__c','111');
        orderMap.put('DestinationPort__c','111');
        orderMap.put('ShippingType__c','海运');

        saveMap.put('base',orderMap);



        Map<String,String> resLip = new Map<String,String>();
        resLip.put('rid', rsp.id);
        resLip.put('cost', '1');


        saveMap.put('reslip',new List<Object>{resLip});

        src.saveJson = EncodingUtil.urlEncode(JSON.serialize(saveMap),'UTF-8');
        src.save();
        System.debug(src.msg);

        List<SalesOrderApplication__c> sor = [select Id from SalesOrderApplication__c where Buyer__c =:acc.Id];

        src.backId = sor.get(0).Id; 
        src.init();

        sor.get(0).Status__c = '已批准';
        update sor ; 
        StockDetailsWebservice.postOverseaOrder(sor.get(0).Id);

    }
}